#include <stdio.h>

#define MAX_ROWS 20
#define MAX_COLS 20
#define TARGET_CHAR 'D'
#define CHAR_COUNT 7

int n, m, flag = 0;
int x1, y1, x2, y2;

char targetChars[CHAR_COUNT] = {'1', 'D', 'S', 'W', 'Y', 'B', 'S'};
char matrix[MAX_ROWS][MAX_COLS];

void dfs(int x, int y, int step);

int main() {
    scanf("%d %d", &n, &m);

    for (int i = 0; i < n; i++) {
        scanf("%s", &matrix[i]);
    }

    for (int i = 0; i < n; i++) {
        for (int k = 0; k < m; k++) {
            if (matrix[i][k] == TARGET_CHAR) {
                dfs(i, k, 1);
            }

            if (flag) {
                x1 = i;
                y1 = k;
                break;
            }
        }
        if (flag) break;
    }

    if (flag) {
        printf("%d %d\n%d %d\n%d", x1, y1, x2, y2, x1 + y1 + x2 + y2);
    } else {
        printf("DSWYBS");
    }

    return 0;
}

void dfs(int x, int y, int step) {
    int tx, ty;
    int next[8][2] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}, {-1, -1}, {-1, 1}, {1, -1}, {1, 1}};

    if (step == CHAR_COUNT - 1) {
        x2 = x;
        y2 = y;
        flag = 1;
        return;
    }

    for (int i = 0; i < 8; i++) {
        tx = x + next[i][0];
        ty = y + next[i][1];

        if (tx >= 0 && tx < n && ty >= 0 && ty < m && matrix[tx][ty] == targetChars[step + 1]) {
            dfs(tx, ty, step + 1);
        }
    }
}

